<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('人事审批')" />
	<th:block th:include="include :: jsonview-css" />
	<th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">

	<form class="form-horizontal m-t" id="signupForm">
		<input class="form-control" type="hidden"  name="taskId" th:value="*{taskId}"/>
		<input class="form-control" type="hidden"  id="processInstanceId" name="processInstanceId" th:value="*{processInstanceId}"/>

		<input class="form-control" type="hidden"  name="businessKey" th:value="${appFrom.leaveNo}"/>
		<h4 class="form-header h4">请假信息</h4>
		<div class="form-group">
			<label class="col-sm-3 control-label">单号：</label>
			<div class="form-control-static"  th:text="${appFrom.leaveNo}">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">标题：</label>
			<div class="form-control-static" th:text="${appFrom.name}">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">请假理由：</label>
			<div class="form-control-static"><pre id="reason"></pre></div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">开始时间：</label>
			<div class="form-control-static" th:text="${#dates.format(appFrom.startTime, 'yyyy-MM-dd hh:mm:ss')}">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">结束时间：</label>
			<div class="form-control-static" th:text="${#dates.format(appFrom.endTime, 'yyyy-MM-dd HH:mm:ss')}">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">申请人：</label>
			<div class="form-control-static" th:text="${appFrom.applyPerson}">
			</div>
		</div>
		<th:block th:include="include :: approvalpage" />
	</form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jsonview-js" />
	<th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var files=new Array();
        $(function () {
            var processInstanceId= $("#processInstanceId").val();
            var url ="/modeler/getProcessDiagram?processInstanceId="+processInstanceId;
            $(".imgcode").attr("src", url);
        });

	    $(function() {
	    	var reason = [[${appFrom.reason}]];
	    	console.log(reason);
	    	if ($.common.isNotEmpty(reason) && reason.length < 2000) {
                $("#reason").text(reason);
	    	} else {
	    		$("#reason").text(reason);
	    	}

	    });


        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val();
            $(this).fileinput({
                'uploadUrl': '/common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {

                files.push({"key": data.response.fileKey,"name": data.response.fileName, "url":data.response.url});
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });


        function submitCheckHandler(status) {
            if ($.validate.form()) {
                var data = $("#signupForm").serializeArray();
                for(var i=0;i<data.length;i++){
                    if(data[i].name=='comment'&&(data[i].value==''||data[i].value==null)){
                        $.modal.alertError("请填写审批意见");
                        return false;
                    }
                }
                if(files!=null||files!=''){
                    for(var i=0;i<files.length;i++){
                        data.push({"name": "files["+i+"].key", "value":files[i].key});
                        data.push({"name": "files["+i+"].name", "value":files[i].name});
                        data.push({"name": "files["+i+"].url", "value":files[i].url});
                    }
                }
                console.log(data);
                $.operate.saveTab("/flow/finishTask", data);
                $.operate.saveTab("/flow/finishTask", data);
            }
        }

    </script>
</body>
</html>